<template>
	<!-- #ifdef MP-WEIXIN -->
	<u-navbar
		:is-back="isback"
		:border-bottom="false"
		back-text="返回"
		back-icon-color="#000"
		:back-text-style="style"
		:title-color="titlecolor"
		:title="title"
		:background="background"
		v-if="SystemInfo.platform != 'windows'"
	>
	<view class="icon-box" slot="right" v-if="isback" @tap="gohome">
		<u-icon  name="home" :size="44"></u-icon>
	</view>
	</u-navbar>
	<!-- #endif -->

</template>
<script>
import {mapState, mapMutations} from 'vuex';
import util from '@/common/util';
export default {
	data() {
		return {
			style: {
				color: '#FFF'
			},
			titlecolor: '#000',
			isback: false
		};
	},
	computed: {
		background() {
			if (this.bgdata && this.bgdata.bg_type) {
				this.titlecolor = this.bgdata.nav_type == 'black' ? '#333' : '#fff';
				if (this.bgdata.bg_type == 1) {
					return {backgroundColor: this.bgdata.nav_bg};
				} else if (this.bgdata.bg_type == 2) {
					let img = util.getimgurl(this.bgdata.nav_bgimg);
					return {background: 'url(' + img + ') no-repeat'};
				}
			} else {
				return {backgroundColor: '#FFFFFF'};
			}
		},
		...mapState({
			hastabbar: state => state.hastabbar,
			SystemInfo: state => state.SystemInfo,
			BottomMenu: state => state.BottomMenu
		})
	},
	props: {
		title: {
			type: String,
			default: ''
		},
		// background:{
		// 	type:Object,
		// 	default(){
		// 		return {
		// 			backgroundColor: '#FFFFFF'
		// 		}
		// 	}
		// },
		bgdata: {
			type: Object,
			default() {
				return {};
			}
		},
		PageId: {
			type: Number,
			default: 0
		}
		// isback: {
		// 	type: Boolean,
		// 	default: true
		// }
	},

	async created() {
		await this.$getWx
		this.gettabs();
	},
	methods: {
		gettabs() {
			if (this.BottomMenu && this.BottomMenu.tablist) {
				this.a_id = this.BottomMenu.tablist.findIndex(a => {
					return this.PageId == a.linkdata.id;
				});

				if (this.a_id > -1) {
					this.isback = false;
				} else {
					this.isback = true;
				}
			}
		},
		gohome() {
			this.Jumpurl(
				{
					type: 1,
					link: '../index/index'
				},
				'switch'
			);
		}
	}
};
</script>

<style>
	.icon-box{
	padding: 12rpx 24rpx 12rpx 12rpx;
	}
</style>
